package algo;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import model.DebateFormat;
import model.Speaker;
import model.SpeakerRole;

public class RoleFilter {
	
	private Set<DebateVertex> vertices;
	
	public RoleFilter(Set<DebateVertex> vertices) {
		this.vertices = vertices;
	}
	
	public RoleFilter removeEdge(Speaker speaker, SpeakerRole role, int debateNumber, DebateFormat format) {
		Set<DebateVertex> copy = createCopy();
		outer: for (DebateVertex v: copy) {
			if (v.speaker == speaker) {
				for (DebateVertex roleVert: v.neighbours) {
					if (roleVert.debateNumber == debateNumber
							&& roleVert.format == format
							&& roleVert.role == role) {
						v.neighbours.remove(roleVert);
						roleVert.neighbours.remove(v);
						break outer;
					}
				}
			}
		}
		return new RoleFilter(copy);		
	}
	
	private Set<DebateVertex> createCopy() {
		Set<DebateVertex> copy = new HashSet<>();
		for (DebateVertex v: vertices) {
			copy.add(new DebateVertex(v));
		}
		return copy;
	}

	public Set<DebateVertex> getVertexSet() {
		return Collections.unmodifiableSet(vertices);
	}
}
